Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

157
Visualizações
What is the difference between javascript require("file") vs require("file.js")?

I have two files.

  • import.js
  • export.js

In import I do:

const export = require('export')

This will successful import the module from export.js. When I do require('export.js') (with file ending) it is also working.

So I was wondering what is the difference there? Is without slower?

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Node.js automatically resolves some extensions. For example: .js, .json, etc. No, it works the same with or without the extension.

about 4 years ago · Juan Pablo Isaza Relatório

0

The difference between import/export and require is that require uses commonjs under the hood. While the import was introduced in ES6.

Even if you use ES6 import it's still transpiled into thecommonjs. But using ES6 is recommended because with the time, it will be widely supported.

Performance-wise the difference will be negligible because the module files are evaluated only once but you will have to benchmark it, if you are very keen on the performance.

about 4 years ago · Juan Pablo Isaza Relatório

0

require in Node.js takes one argument which can be either module name or path. You can read for more info.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda